package com.LeeCode;

/**
 * 从二叉搜索树到更大和树
 */

public class Code1038 {
    public static void main(String[] args) {

    }

    private int sum = 0;

    public TreeNode bstToGst(TreeNode root) {
        dfs(root);
        return root;
    }

    private void dfs(TreeNode root) {
        if (root == null) return;
        dfs(root.right);
        sum += root.val;
        root.val = sum;
        dfs(root.left);
    }
}
